package com.elm.serviceimpl;

import java.util.List;


import com.elm.dao.SellerDao;
import com.elm.daoimpl.SellerDaoImpl;
import com.elm.model.PageBean;
import com.elm.model.Role;
import com.elm.model.Seller;
import com.elm.service.SellerService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class SellerServiceImpl implements SellerService{
	SellerDao sdao = new SellerDaoImpl(); 
		
	@Override
	public Seller sellerLogin(Seller s) {
		// TODO Auto-generated method stub
		return sdao.validateUser(s);
	}

	@Override
	public Role getRoleBySid(int Sid) {
		// TODO Auto-generated method stub
		return sdao.getRoleBySid(Sid);
	}

	@Override
	public boolean validateSname(String sname) {
		// TODO Auto-generated method stub
		return sdao.validateSname(sname);
	}

	@Override
	public boolean validateUphone(String sphone) {
		// TODO Auto-generated method stub
		return sdao.validateSphone(sphone);
	}

	@Override
	public boolean sellerRegist(Seller s) {
		// TODO Auto-generated method stub
		return sdao.addSeller(s);
	}

	@Override
	public List<Seller> getAllSellers(PageBean p) {
		// TODO Auto-generated method stub
		return sdao.findAllSellers(p);
	}

	@Override
	public int getSellercount() {
		// TODO Auto-generated method stub
		return sdao.findSellerCount();
	}

	@Override
	public List<Seller> findSellerByNameOrGenre(String shopname, String shopgenre,PageBean p) {
		// TODO Auto-generated method stub
		return sdao.findSellerByNameOrGenre(shopname, shopgenre, p);
	}

	@Override
	public Seller findSellerById(int sellerid) {
		// TODO Auto-generated method stub
		return sdao.findSellerById(sellerid);
	}
	/**
	 * 查询全部商家
	 */
		JSONObject json = new JSONObject();
		public JSONObject FindAllSellers(int start, int pageSize) {
			// TODO Auto-generated method stub
			json.put("total",sdao.getSellersCount());
			json.put("rows", JSONArray.fromObject(sdao.FindAllSellers(start, pageSize)));
			return json;
		}
	/**
	 * 通过商家名字来查找商家
	 */
		@Override
		public JSONObject FindSellerByName(int start, int pageSize, String searchname) {
			// TODO Auto-generated method stub
			json.put("total", sdao.getSellersCountByName(searchname));
			json.put("rows", JSONArray.fromObject(sdao.FindSellerByName(start, pageSize, searchname)));
			return json;
		}
	/**
	 * 通过商家id来删除商家
	 */
		@Override
		public boolean deleteseller(int srids) {
			// TODO Auto-generated method stub
			if(sdao.deleteseller(srids)==true){
				return true;
			}
			return false;
		}

	/**
	 * 查询全部申请信息
	 */
	public JSONObject FindAllApplySellers(int start, int pageSize) {
		JSONObject json = new JSONObject();
		json.put("total",sdao.getApplySellersCount());
		json.put("rows", JSONArray.fromObject(sdao.FindAllApplySellers(start, pageSize)));
		return json;
	}

	/**
	 * 通过商家名来查找申请信息
	 */

	public JSONObject FindApplySellerByName(int start, int pageSize, String searchname) {
		JSONObject json = new JSONObject();
		json.put("total",sdao.getApplySellerCountByName(searchname));
		json.put("rows", JSONArray.fromObject(sdao.FindApplySellerByName(start, pageSize, searchname)));
		return json;
	}

	/**
	 * 通过id来通过开店申请
	 */
	public boolean passseller(int srids) {
		// TODO Auto-generated method stub
		if(sdao.passseller(srids)==true){
			return true;
		}
		return false;
	}

	/**
	 * 查询全部过往商家
	 */
	public JSONObject FindOldSellers(int start, int pageSize) {
		JSONObject json = new JSONObject();
		json.put("total",sdao.getOldSellersCount());
		json.put("rows", JSONArray.fromObject(sdao.FindOldSellers(start, pageSize)));
		return json;
	}

	/**
	 * 通过名字查找过往商家
	 */
	public JSONObject FindOldSellerByName(int start, int pageSize, String searchname) {
		JSONObject json = new JSONObject();
		json.put("total",sdao.getOldSellerCountByName(searchname));
		json.put("rows", JSONArray.fromObject(sdao.FindOldSellerByName(start, pageSize, searchname)));
		return json;
	}

	/**
	 * 通过id来还原商家
	 */
	public boolean restoreseller(int seid) {
		// TODO Auto-generated method stub
		if(sdao.restoreseller(seid)==true){
			return true;
		}
		return false;
	}
	@Override
	public int updateSeller(Seller seller ,int sellerid) {
		// TODO Auto-generated method stub
		int flag=0;
		flag=sdao.updateSeller(seller, sellerid);
		
		return flag;
	}
}
